package com.mxpio.erp.equipment.service.impl;

import com.mxpio.erp.common.equipment.entity.EquipmentRepair;
import com.mxpio.erp.common.equipment.entity.FaultType;
import com.mxpio.erp.common.equipment.service.FaultTypeService;
import com.mxpioframework.common.vo.Result;
import com.mxpioframework.jpa.JpaUtil;
import com.mxpioframework.system.service.impl.BaseServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;

@Service
public class FaultTypeServiceImpl extends BaseServiceImpl<FaultType> implements FaultTypeService {
    @Override
    @Transactional
    public Result<?> deleteByIds(String ids) {
        if (StringUtils.isBlank(ids)){
            return Result.error("入参为空，请检查");
        }
        Long count = JpaUtil.linq(EquipmentRepair.class).in("faultTypeCode", Arrays.asList(ids.split(","))).count();
        if (count>0){
            return Result.error("故障类型已被使用，不能删除");
        }
        this.delete(FaultType.class,ids.split(","));
        return Result.OK();
    }
}
